package com.zqxq.lottery.entity.o2o.sys;

import com.baomidou.mybatisplus.plugins.Page;
import com.zqxq.common.utils.DispatcherUtils;
import com.zqxq.common.utils.PageCopy;
import com.zqxq.lottery.entity.po.sys.SysBannerPO;
import com.zqxq.lottery.entity.vo.sys.SysBannerVO;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2018/03/14 16:13
 */
public class SysBannerO2O {

    public static SysBannerVO toVO(SysBannerPO po) {
        if (po == null) {
            return null;
        }
        SysBannerVO sysBannerVO = new SysBannerVO();
        sysBannerVO.setId(DispatcherUtils.parseString(po.getId()));
        sysBannerVO.setTitle(po.getTitle());
        sysBannerVO.setImgUrl(po.getImg_url());
        sysBannerVO.setLinkUrl(po.getLink_url());
        sysBannerVO.setSort(DispatcherUtils.parseString(po.getSort()));
        sysBannerVO.setStatus(DispatcherUtils.parseString(po.getStatus()));
        sysBannerVO.setType(DispatcherUtils.parseString(po.getType()));
        sysBannerVO.setClickNum(DispatcherUtils.parseString(po.getClick_num()));
        sysBannerVO.setCreateTime(DispatcherUtils.parseDateTimeStr(po.getCreate_time()));
        sysBannerVO.setUpdateTime(DispatcherUtils.parseDateTimeStr(po.getUpdate_time()));
        return sysBannerVO;
    }

    public static Page<SysBannerVO> toPageVO(Page<SysBannerPO> page){
        Page<SysBannerVO> result = PageCopy.copyProperty(page, null);
        if(page != null){
            List<SysBannerPO> poList = page.getRecords();
            List<SysBannerVO> voList = toVOList(poList);
            result.setRecords(voList);
        }
        return result;
    }

    public static SysBannerPO toPO(SysBannerVO vo) {
        if (vo == null) {
            return null;
        }
        SysBannerPO sysBannerPO = new SysBannerPO();
        sysBannerPO.setId(DispatcherUtils.parseLong(vo.getId()));
        sysBannerPO.setTitle(vo.getTitle());
        sysBannerPO.setImg_url(vo.getImgUrl());
        sysBannerPO.setLink_url(vo.getLinkUrl());
        sysBannerPO.setSort(DispatcherUtils.parseInteger(vo.getSort()));
        sysBannerPO.setStatus(DispatcherUtils.parseInteger(vo.getStatus()));
        sysBannerPO.setType(DispatcherUtils.parseInteger(vo.getType()));
        sysBannerPO.setClick_num(DispatcherUtils.parseInteger(vo.getClickNum()));
        sysBannerPO.setCreate_time(DispatcherUtils.parseDateTime(vo.getCreateTime()));
        sysBannerPO.setUpdate_time(DispatcherUtils.parseDateTime(vo.getUpdateTime()));
        return sysBannerPO;
    }

    public static List<SysBannerVO> toVOList(List<SysBannerPO> list){
        List<SysBannerVO> result = new ArrayList<>();
        if(list != null && list.size() > 0){
            for (SysBannerPO po : list) {
                result.add(toVO(po));
            }
        }
        return result;
    }


}
